﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using DBSchemaViewer.BackEnd.CommonHelpers;


namespace DBSchemaViewer.BackEnd.Entities
{
    public class EntityRelation : EntityBase
    {
        public int TableOriginID { get; set; }
        public int TableDestinationID { get; set; }

        public ObservableCollection<EntityRelationField> RelationFields { get; set; }


        /// <summary>
        /// Same as Relation Fields it converts the RelationFiels LIst to an ObervableCollection
        /// </summary>
        public List<EntityRelationField> LstRelationFields
        {
            set { RelationFields = ListConverter<EntityRelationField>.ConvertListToObservableCollection(value); }
        }

        
        /// <summary>
        /// Returns a copy of the entity (by using this we can just work with the copied entity without affecting
        /// the original one and relations fields list).
        /// </summary>
        /// <returns></returns>
        public EntityRelation Copy()
        {
            EntityRelation copiedRelation = new EntityRelation();
            copiedRelation.InternalID = this.InternalID;
            copiedRelation.TableOriginID = this.TableOriginID;
            copiedRelation.TableDestinationID = this.TableDestinationID;

            copiedRelation.RelationFields = new ObservableCollection<EntityRelationField>();

            foreach (EntityRelationField currentField in RelationFields)
            {
                EntityRelationField newField = new EntityRelationField();

                newField.FieldOrigin = currentField.FieldOrigin;
                newField.FieldDestination = currentField.FieldDestination;

                copiedRelation.RelationFields.Add(newField);
            }

            return copiedRelation;
        }
    }

    public class EntityRelations : List<EntityRelation>
    {
    }

}
